return {
  {
    "olimorris/codecompanion.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-treesitter/nvim-treesitter",
    },
    init = function()
      require("ai.codecompanion.spinner"):init()
      require("ai.codecompanion.fidget"):init()
    end,
    config = function()
      require("codecompanion").setup({
        adapters = {
          deepseek_r1 = function()
            return require("codecompanion.adapters").extend("ollama", {
              name = "ollama",
              schema = {
                model = {
                  default = "deepseek-r1:8b",
                },
                num_ctx = {
                  default = 16384,
                },
                num_predict = {
                  default = -1,
                },
              },
            })
          end,

          ollama_codellama = function()
            return require("codecompanion.adapters").extend("ollama", {
              name = "ollama_codellama ",
              schema = {
                model = {
                  default = "codellama:7b",
                },
                num_ctx = {
                  default = 16384,
                },
                num_predict = {
                  default = -1,
                },
              },
            })
          end,

          deepseek = function()
            return require("codecompanion.adapters").extend("deepseek", {
              name = "deepseek",
              env = {
                api_key = function()
                  return os.getenv("DEEPSEEK_API_KEY")
                end,
              },
              schema = {
                model = {
                  default = "deepseek-coder",
                },
              },
            })
          end,

          siliconflow_r1 = function()
            return require("codecompanion.adapters").extend("deepseek", {
              name = "siliconflow_r1",
              url = "https://api.siliconflow.cn/v1/chat/completions",
              env = {
                api_key = function()
                  return os.getenv("DEEPSEEK_API_KEY_S")
                end,
              },
              schema = {
                model = {
                  default = "deepseek-ai/DeepSeek-R1",
                  choices = {
                    ["deepseek-ai/DeepSeek-R1"] = { opts = { can_reason = true } },
                    "deepseek-ai/DeepSeek-V3",
                  },
                },
              },
            })
          end,

          siliconflow_v3 = function()
            return require("codecompanion.adapters").extend("deepseek", {
              name = "siliconflow_v3",
              url = "https://api.siliconflow.cn/v1/chat/completions",
              env = {
                api_key = function()
                  return os.getenv("DEEPSEEK_API_KEY_S")
                end,
              },
              schema = {
                model = {
                  default = "deepseek-ai/DeepSeek-V3",
                  choices = {
                    "deepseek-ai/DeepSeek-V3",
                    ["deepseek-ai/DeepSeek-R1"] = { opts = { can_reason = true } },
                  },
                },
              },
            })
          end,

          aliyun_deepseek = function()
            return require("codecompanion.adapters").extend("deepseek", {
              name = "aliyun_deepseek",
              url = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
              env = {
                api_key = function()
                  return os.getenv("DEEPSEEK_API_ALIYUN")
                end,
              },
              schema = {
                model = {
                  default = "deepseek-r1",
                  choices = {
                    ["deepseek-r1"] = { opts = { can_reason = true } },
                  },
                },
              },
            })
          end,
          -- 阿里千问
          -- https://help.aliyun.com/zh/model-studio/getting-started/models?spm=a2c4g.11186623.0.0.ce3c4823l7PTRL#9f8890ce29g5u
          aliyun_qwen = function()
            return require("codecompanion.adapters").extend("openai_compatible", {
              name = "aliyun_qwen",
              env = {
                url = "https://dashscope.aliyuncs.com",
                api_key = function()
                  return os.getenv("DEEPSEEK_API_ALIYUN")
                end,
                chat_url = "/compatible-mode/v1/chat/completions",
              },
              schema = {
                model = {
                  default = "qwen-coder-plus-latest",
                },
              },
            })
          end,
        },
        strategies = {
          chat = {
            adapter = "deepseek_r1",
            keymaps = {
              send = {
                modes = { n = "<C-s>", i = "<C-s>" },
              },
              close = {
                modes = { n = "<C-c>", i = "<C-c>" },
              },
            },
          },
          inline = { adapter = "ollama_codellama" },
        },
        opts = {
          language = "Chinese",
        },
        display = {
          action_palette = {
            width = 95,
            height = 10,
            prompt = "Prompt ", -- Prompt used for interactive LLM calls
            provider = "default", -- Can be "default", "telescope", or "mini_pick". If not specified, the plugin will autodetect installed providers.
            opts = {
              show_default_actions = true, -- Show the default actions in the action palette?
              show_default_prompt_library = true, -- Show the default prompt library in the action palette?
            },
          },
        },
        prompt_library = {
          ["DeepSeek Explain"] = require("ai.codecompanion.prompts.deepseek-explain"),
          ["DeepSeek LSP Explain"] = require("ai.codecompanion.prompts.deepseek-lsp-explain"),
          ["DeepSeek Optimize"] = require("ai.codecompanion.prompts.deepseek-optimize"),
        },
      })

      -- 设置快捷键
      vim.keymap.set("n", "<leader>aa", "<cmd>CodeCompanionAction<CR>", { desc = "CodeCompanion Action" })
      vim.keymap.set("n", "<leader>an", "<cmd>CodeCompanionChat<CR>", { desc = "CodeCompanion Chat New" })
      vim.keymap.set("n", "<leader>ac", "<cmd>CodeCompanionChat Toggle<CR>", { desc = "CodeCompanion Chat Toggle" })
      vim.keymap.set("n", "<leader>ai", "<cmd>CodeCompanion<CR>", { desc = "CodeCompanion Inline" })
      vim.keymap.set("n", "<leader>ad", "<cmd>CodeCompanionCmd<CR>", { desc = "CodeCompanion Cmd" })

      vim.keymap.set("v", "<leader>aa", "<cmd>CodeCompanionAction<CR>", { desc = "CodeCompanion Action" })
      vim.keymap.set("v", "<leader>an", "<cmd>CodeCompanionChat<CR>", { desc = "CodeCompanion Chat New" })
      vim.keymap.set("v", "<leader>ac", "<cmd>CodeCompanionChat Toggle<CR>", { desc = "CodeCompanion Chat Toggle" })
      vim.keymap.set("v", "<leader>ai", "<cmd>CodeCompanion<CR>", { desc = "CodeCompanion Inline" })
      vim.keymap.set("v", "<leader>ad", "<cmd>CodeCompanionCmd<CR>", { desc = "CodeCompanion Cmd" })
    end,
  },
}
